for each door from left to right
if number is behind door
return true
return falseThis algorithm does n+2 steps at most, or n+ some constant.
Therefore, for linear search:
if no doors
return false
if number behind middle door
return true
else if number > middle door
search left half
else if number < middle door
search right halfIf you had to sort the data first, you have to look at all the data first (O(n)) before you can run efficient binary searches (O(\log n)).